package com.ruoyi.project.hissystem.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hissystem.domain.ProjectFee;
import com.ruoyi.project.hissystem.service.IHisProjectFeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 高向前
 * @date : 10:37 2021/8/18
 */

@RestController
@RequestMapping("/hissystem/projectFee")
public class ProjectFeeController extends BaseController {
    @Autowired
    private IHisProjectFeeService hisProjectFeeService;

    //查询所有
    @PreAuthorize("@ss.hasPermi('hissystem:projectFee:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectFee projectFee){
        //System.out.println("00000000000000000000000000000");
        startPage();
        List<ProjectFee> projectFeeList = hisProjectFeeService.selectProjectFeeList(projectFee);
        return getDataTable(projectFeeList);
    }

    //查询项目类型
    @PreAuthorize("@ss.hasPermi('hissystem:projectFee:selectType')")
    @GetMapping("/selectType")
    public AjaxResult selectType(){
        List<ProjectFee> types = hisProjectFeeService.selectProjectFeeType();
        return AjaxResult.success(types);
    }

    //新增项目费用
    @Log(title = "项目费用管理", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('hissystem:projectFee:add')")
    @PostMapping("/addProjectFee")
    public AjaxResult addProjectFee(@RequestBody ProjectFee projectFee){
        projectFee.setCreateBy(SecurityUtils.getUsername());
        int rows = hisProjectFeeService.addProjectFee(projectFee);
        return toAjax(rows);
    }

    //修改项目费用之前根据Id查询
    @PreAuthorize("@ss.hasPermi('hissystem:projectFee:update')")
    @GetMapping("/{projectId}")
    public AjaxResult selectProjectFeeById(@PathVariable Integer projectId){
        ProjectFee projectFees = hisProjectFeeService.selectProjectFeeById(projectId);
        return AjaxResult.success(projectFees);
    }

    //修改项目费用
    @Log(title = "项目费用管理", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('hissystem:projectFee:update')")
    @PutMapping("/updateProjectFee")
    public AjaxResult updateProjectFee(@RequestBody ProjectFee projectFee){
        int rows = hisProjectFeeService.updateProjectFee(projectFee);
        return toAjax(rows);
    }

    //删除项目费用
    @Log(title = "项目费用管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{projectIds}")
    @PreAuthorize("@ss.hasPermi('hissystem:projectFee:remove')")
    public AjaxResult deleteProjectFees(@PathVariable int[] projectIds){
        return toAjax(hisProjectFeeService.deleteProjectFees(projectIds));
    }
}
